Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherent associated types: Better type inference #108430

Closed
wants to merge 1 commit into from

Conversation

fmease
Copy link
Member

@fmease fmease commented Feb 24, 2023

Follow-up to #105961.

If we are in a FnCtxt, use the provided InferCtxt to re-relate the Self type of the applicable IAT candidate with the one of the impl to constrain and possibly subsequently solve any inference variables in the Self type. Enables type inference for IATs in bodies of functions, closures, and consts.

CC @aliemjay: I've reintroduced normalize to AstConv and you probably have an opinion about this.

@rustbot label F-inherent_associated_types
r? @jackh726 (feel free to reassign though)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-inherent_associated_types `#![feature(inherent_associated_types)]` labels Feb 24, 2023
@@ -0,0 +1,16 @@
// check-pass
Copy link
Member Author

@fmease fmease Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this test is still useful since it's kind of superseded by inference.rs. I've solely kept it to explicitly demonstrate that bugs/ice-substitution.rs is fixed in this PR.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease marked this pull request as ready for review February 24, 2023 18:23
}
}
} else {
assert!(!probe_impl_substs.needs_infer());
Copy link
Member Author

@fmease fmease Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this holds true in general.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right approach.

Instead, I think we need to emit something like a ty::Alias(ty::Inherent, ..) instead of eagerly normalizing and registering bounds within astconv. Adding all this machinery to astconv, then having to rip it out later seems like a lot of work for nothing.

More abstractly, I would like to see more design work on this feature rather than incremental tweaks to behavior like this that still leave bigger questions unanswered.

@@ -516,6 +516,10 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
// There's no place to record types from signatures?
}

fn register_predicate_obligations(&self, _: PredicateObligations<'tcx>) {
// There's no place to track this, so just let it go.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right. We should at least ICE here.

// FIXME(inherent_associated_types): To fully *confirm* the *probed* candidate, we still
// need to relate the Self-type with fresh item substs & register region obligations for
// regionck to prove/disprove.
// FIXME(fmease, inherent_associated_types): Register WF obligations for the Self type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be fixed by representing it as a projection, so we see the Self type during wfcheck.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do plan on implementing something akin to InherentProjection at least experimentally as we've already discussed here. Since I haven't looked into it that much yet, I wasn't sure if this covers wf-checking and inference for the Self type or just for the parameters & bounds of an inherent GAT.

@fmease
Copy link
Member Author

fmease commented Feb 24, 2023

Closing in favor of a more principled approach

@fmease fmease closed this Feb 24, 2023
@fmease fmease deleted the iat-better-infer branch March 9, 2023 23:42
compiler-errors added a commit to compiler-errors/rust that referenced this pull request May 8, 2023
…compiler-errors

Introduce `AliasKind::Inherent` for inherent associated types

Allows us to check (possibly generic) inherent associated types for well-formedness.
Type inference now also works properly.

Follow-up to rust-lang#105961. Supersedes rust-lang#108430.
Fixes rust-lang#106722.
Fixes rust-lang#108957.
Fixes rust-lang#109768.
Fixes rust-lang#109789.
Fixes rust-lang#109790.

~Not to be merged before rust-lang#108860 (`AliasKind::Weak`).~

CC `@jackh726`
r? `@compiler-errors`

`@rustbot` label T-types F-inherent_associated_types
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 20, 2023
…compiler-errors

Introduce `AliasKind::Inherent` for inherent associated types

Allows us to check (possibly generic) inherent associated types for well-formedness.
Type inference now also works properly.

Follow-up to rust-lang#105961. Supersedes rust-lang#108430.
Fixes rust-lang#106722.
Fixes rust-lang#108957.
Fixes rust-lang#109768.
Fixes rust-lang#109789.
Fixes rust-lang#109790.

~Not to be merged before rust-lang#108860 (`AliasKind::Weak`).~

CC `@jackh726`
r? `@compiler-errors`

`@rustbot` label T-types F-inherent_associated_types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-inherent_associated_types `#![feature(inherent_associated_types)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants